package pkg.hicph.org;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class EndOfDayDialog extends Activity implements OnClickListener  {
	
    
    public TextView dayInfo;
    public Button confirmButton;
    
    private String auxDayStory;
    private String[] introSnippetHappy = {
    	"You feel more empowered after a day like this, your hopes get higher:",
    	"Things are getting better. After today, you feel it.",
    	"You have a calm mind after a good day. Good feelings for tomorrow.",
    	"You go to rest with a smile after today, hoping it keeps going like that."
    };
    
    private String[] introSnippetNormal = {
        "You feel: 'Well, another useless day'. Will tomorrow be the same again?",
        "Days like this don't help you much. You can only hope for tomorrow.",
        "Another day goes by and nothing changes.You feel a bit empty inside.",
        "You have the hope that tomorrow will be a better day than today."
    };
    
    private String[] introSnippetSad = {
        "By the end of the day, you were really sad with what you did:",
        "How not to feel a desperate after a day like this?",
        "'Terrible day', you think. 'Why can't things be different?'",
        "Everything feels pointless after what you did today:"
    };


	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  
	  setContentView(R.layout.endofdaydialog);
	  
	  registerViews();
	  setupOnClickListeners();
	  
	  this.setTitle("End of Day " + Utils.currentDay);
	  
	  auxDayStory = Utils.player.dayStory.replace(". ", ". ").trim();

	  if(Utils.player.mood>=70){
		  dayInfo.setText(introSnippetHappy[(int)(Math.random()*4)] + "\n\n" + auxDayStory);
	  }
	  else if(Utils.player.mood>=40){
		  dayInfo.setText(introSnippetNormal[(int)(Math.random()*4)] + "\n\n" + auxDayStory);
	  }
	  else {
		  dayInfo.setText(introSnippetSad[(int)(Math.random()*4)] + "\n\n" + auxDayStory);
	  }
	  
	  
	  
	  
	  
	  
	}
	
	
//	private void loadPrefs() {
//		
//		String actionName;
//		
//    	preferences  = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
//    	
//    	actionName = preferences.getString("nextActionName", "");
//    	
//    	Log.d("DIALOG","loaded: " + actionName);
//    	
//    	actionToPerform = Utils.nextAction;
//    	
//    	actionToPerform = Utils.getActionByName(actionName);
//    	Log.d("DIALOG","action: " + actionToPerform.name);
//        
//	}
	
	
	private void registerViews() {
			
		 confirmButton = (Button) this.findViewById(R.id.day_confirm_button);
		 dayInfo = (TextView) this.findViewById(R.id.day_dialog_info);
		 
	}

	
	public void setupOnClickListeners() {
        
		confirmButton.setOnClickListener(this);

    }
    
	
    public void onClick(View V) {
    	
    	switch(V.getId()) {
    	
    	case R.id.day_confirm_button:
    		
    		// COMPUTES ACTION
    		Log.d("END OF DAY","confirmed");
    		
    		Utils.gamePhase = Utils.NORMAL;
    		
    		// CLOSES THE DIALOG
    		finish();
    		
    		break;
    		
    	}

    }
    
    
    
    public void finishActivity() {
    	this.finish();
    }

}


